package com.pentofab.payrollmanagement.ui.controller;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

import com.pentofab.payrollmanagement.dao.model.SalaryAdvanceDetail;
import com.pentofab.payrollmanagement.ui.control.CustomTextField;

public class AdvanceRecoveryController extends AbstractUIController {


	@FXML
	private ResourceBundle resources;

	@FXML
	private URL location;

	@FXML
	private TextField advAmount;

	@FXML
	private TextField blAmount;

	@FXML
	private TextField empName;

	@FXML
	private GridPane grid;

	@FXML
	private CustomTextField recovAmount;

	private Stage dialogStage;
	private SalaryAdvanceDetail salaryAdvance;

	@FXML
	void handleCancel(ActionEvent event) {
		refreshUI();
		dialogStage.close();
	}

	@FXML
	void handleOk(ActionEvent event) {

		String recoveryAmount = recovAmount.getText().trim();

		if(recoveryAmount.equals("")){
			showInfo("Invalid recovery amount");
			return;
		}
		if(!showConfirmDialog("Would you like to recover an amount '"+recovAmount.getText().trim())){
			return ;
		}
		System.out.println("Recovering");
	}

	void initialize() {


	}

	@Override
	public Parent getView() {
		// TODO Auto-generated method stub
		return grid;
	}

	@Override
	public String getTitle() {
		// TODO Auto-generated method stub
		return "Advance Recovery";
	}

	@Override
	public void refreshUI(Object... args) {

		empName.clear();
		advAmount.clear();
		blAmount.clear();
		recovAmount.clear();
	}
	public void setDialogStage(Stage dialogStage) {
		this.dialogStage = dialogStage;
	}
	public void setAdvance(SalaryAdvanceDetail salaryAdvance){

		this.salaryAdvance = salaryAdvance;
		empName.setText(salaryAdvance.getEmployeeIdCol());
		advAmount.setText(salaryAdvance.getAdvAmt());
		blAmount.setText(salaryAdvance.getBalance());


	}

}
